home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8615 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: hamlet.uncg.edu!b_lee2
  2. From: "Bin . Lee" <b_lee2@hamlet.uncg.edu>
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Safest way to define a string
  5. Date: Sat, 17 Feb 1996 12:59:37 -0500
  6. Organization: The University of North Carolina at Greensboro
  7. Message-ID: <Pine.SOL.3.91.960217124454.26354A-100000@hamlet.uncg.edu>
  8. NNTP-Posting-Host: hamlet.uncg.edu
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11.  
  12.  
  13. Hi: Folks:
  14.  
  15. This is a simplest question, I think many of you know the answer, please 
  16. help me and send me a email.
  17.  
  18. Question is: which is the safest way to define a string ?
  19.  
  20. a. some one told me to use the following approach:
  21. const int STRLEN = 100;
  22. char strTest[STRLEN + 1];
  23.  
  24. Then always use strTest[STRLEN] =0;
  25. This is OK, but if I have to pass a 2D array to function,
  26. it will looks like 
  27.  
  28. int TestFun( char strTest2D[][STRLEN + 1] );
  29. This is really awkward.
  30.  
  31. If I just want to use array, is it safe to use Array class ? or string 
  32. class ?
  33.  
  34. Anyway, my real question is how to prevent memory overflow for array ?
  35. can I overload global subscript operation [] and unary operator * ?
  36.  
  37. Thanks in advance, this is important for me, please reply me in mail.
  38. I do not want to miss it.
  39.  
  40.  
  41. Cheers
  42.  
  43.  
  44.